package com.loan.web.pdf.controller;

import com.loan.common.annotation.Log;
import com.loan.common.core.controller.BaseController;
import com.loan.common.core.domain.AjaxResult;
import com.loan.common.core.page.TableDataInfo;
import com.loan.common.enums.BusinessType;
import com.loan.common.utils.poi.ExcelUtil;
import com.loan.system.domain.AssistType;
import com.loan.system.service.IAssistTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 数据配置Controller
 *
 * @author Sophia
 * @date 2024-01-28
 */
@RestController
@RequestMapping("/system/assist")
public class AssistTypeController extends BaseController {
    @Autowired
    private IAssistTypeService assistTypeService;

    /**
     * 查询数据配置列表
     */
    @PreAuthorize("@ss.hasPermi('system:assist:list')")
    @GetMapping("/list")
    public TableDataInfo list(AssistType assistType) {
        startPage();
        List<AssistType> list = assistTypeService.selectAssistTypeList(assistType);
        return getDataTable(list);
    }

    /**
     * 导出数据配置列表
     */
    @PreAuthorize("@ss.hasPermi('system:assist:export')")
    @Log(title = "数据配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AssistType assistType) {
        List<AssistType> list = assistTypeService.selectAssistTypeList(assistType);
        ExcelUtil<AssistType> util = new ExcelUtil<AssistType>(AssistType.class);
        util.exportExcel(response, list, "数据配置数据");
    }

    /**
     * 获取数据配置详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:assist:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(assistTypeService.selectAssistTypeById(id));
    }

    /**
     * 新增数据配置
     */
    @PreAuthorize("@ss.hasPermi('system:assist:add')")
    @Log(title = "数据配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AssistType assistType) {
        return toAjax(assistTypeService.insertAssistType(assistType));
    }

    /**
     * 修改数据配置
     */
    @PreAuthorize("@ss.hasPermi('system:assist:edit')")
    @Log(title = "数据配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AssistType assistType) {
        return toAjax(assistTypeService.updateAssistType(assistType));
    }

    /**
     * 删除数据配置
     */
    @PreAuthorize("@ss.hasPermi('system:assist:remove')")
    @Log(title = "数据配置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(assistTypeService.deleteAssistTypeByIds(ids));
    }
}
